import Vue from 'vue'
import Router from 'vue-router'

// in development-env not use lazy-loading, because lazy-loading too many pages will cause webpack hot update too slow. so only in production use lazy-loading;
// detail: https://panjiachen.github.io/vue-element-admin-site/#/lazy-loading

Vue.use(Router)

/* Layout */
import Layout from '../views/layout/Layout'

/**
* hidden: true                   if `hidden:true` will not show in the sidebar(default is false)
* alwaysShow: true               if set true, will always show the root menu, whatever its child routes length
*                                if not set alwaysShow, only more than one route under the children
*                                it will becomes nested mode, otherwise not show the root menu
* redirect: noredirect           if `redirect:noredirect` will no redirect in the breadcrumb
* name:'router-name'             the name is used by <keep-alive> (must set!!!)
* meta : {
    title: 'title'               the name show in submenu and breadcrumb (recommend set)
    icon: 'svg-name'             the icon show in the sidebar
    breadcrumb: false            if false, the item will hidden in breadcrumb(default is true)
  }
**/
export const constantRouterMap = [
  { path: '/login', component: () => import('@/views/login/index'), hidden: true },
  { path: '/404', component: () => import('@/views/404'), hidden: true },

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    name: 'Dashboard',
    hidden: true,
    children: [{
      path: 'dashboard',
      component: () => import('@/views/dashboard/index')
    }]
  }
]

export const asyncRouterMap = [
  {
    id: '1',
    path: '/dashboard',
    component: Layout,
    redirect: '/dashboard/index',
    name: 'dashboard',
    meta: { title: 'dashboard', icon: 'home' },
    titleName: 'dashboard',
    children: [
      {
        path: 'index',
        id: '1-1',
        name: 'index',
        component: () => import('@/views/dashboard/index'),
        meta: { title: 'dashboard', icon: 'home' },
        titleName: 'dashboard'
      },
      {
        path: 'accountSettings',
        id: '1-2',
        name: 'accountSettings',
        component: () => import('@/views/dashboard/accountSettings'),
        meta: { title: 'account', icon: 'setup' },
        titleName: 'account'
      }
    ]
  },
  {
    id: '2',
    path: '/order',
    component: Layout,
    redirect: '/order/orderList/sonOrderList',
    name: 'order',
    meta: { title: 'order', icon: 'order' },
    titleName: 'order',
    children: [
      {
        path: 'orderList',
        id: '2-1',
        component: () => import('@/views/order/orderList/index'),
        redirect: '/order/orderList/sonOrderList',
        meta: { title: 'orderList', icon: 'orderM' },
        titleName: 'orderList',
        children: [
          {
            path: 'sonOrderList',
            id: '2-1-1',
            component: () => import('@/views/order/orderList/sonOrderList'),
            name: 'sonOrderList',
            titleName: 'sonOrder',
            meta: { title: 'sonOrder' }
          },
          {
            path: 'sonOrderDetail/:id',
            id: '2-1-3',
            component: () => import('@/views/order/orderList/sonOrderDetail'),
            name: 'sonOrderDetail',
            titleName: 'orderDetail',
            meta: { title: 'orderDetail' },
            hidden: true
          },
          {
            path: 'confirmReceipt',
            id: '2-1-2',
            component: () => import('@/views/order/orderList/confirmReceipt'),
            name: 'confirmReceipt',
            titleName: 'goodsList',
            meta: { title: 'goodsList' }
          }
        ]
      },
      {
        path: 'afterSaleList',
        id: '2-2',
        component: () => import('@/views/order/afterSaleList/index'),
        redirect: '/order/afterSaleList/returnOrderList',
        meta: { title: 'afterList', icon: 'orderM' },
        titleName: 'afterList',
        children: [
          {
            path: 'returnOrderList',
            id: '2-2-1',
            component: () => import('@/views/order/afterSaleList/returnOrderList'),
            name: 'returnOrderList',
            titleName: 'returnList',
            meta: { title: 'returnList' },
            children: []
          }
        ]
      }
    ]
  },
  {
    id: '3',
    path: '/module',
    component: Layout,
    redirect: '/module/icon',
    name: 'module',
    meta: { title: 'module', icon: 'example' },
    titleName: 'module',
    children: [
      {
        path: 'icon',
        id: '3-1',
        name: 'icon',
        component: () => import('@/views/module/icon'),
        meta: { title: 'icon', icon: 'icon' },
        titleName: 'icon'
      },
      {
        path: 'button',
        id: '3-2',
        name: 'button',
        component: () => import('@/views/module/button'),
        meta: { title: 'button', icon: 'btn' },
        titleName: 'button'
      },
      {
        path: 'cascade',
        id: '3-3',
        name: 'cascade',
        component: () => import('@/views/module/cascade'),
        meta: { title: 'cascade', icon: 'cascade' },
        titleName: 'cascade'
      },
      {
        path: 'city',
        id: '3-4',
        name: 'city',
        component: () => import('@/views/module/city'),
        meta: { title: 'city', icon: 'city' },
        titleName: 'city'
      },
      {
        path: 'tree',
        id: '3-5',
        name: 'tree',
        component: () => import('@/views/module/tree'),
        meta: { title: 'tree', icon: 'tree' },
        titleName: 'tree'
      },
      {
        path: 'table',
        id: '3-6',
        name: 'table',
        component: () => import('@/views/module/table'),
        meta: { title: 'table', icon: 'table' },
        titleName: 'table'
      },
      {
        path: 'calendar',
        id: '3-7',
        name: 'calendar',
        component: () => import('@/views/module/calendar'),
        meta: { title: 'calendar', icon: 'calendar' },
        titleName: 'calendar'
      },
      {
        path: 'images',
        id: '3-8',
        name: 'images',
        component: () => import('@/views/module/images'),
        meta: { title: 'images', icon: 'image' },
        titleName: 'images'
      },
      {
        path: 'textEditor',
        id: '3-9',
        name: 'textEditor',
        component: () => import('@/views/module/textEditor'),
        meta: { title: 'textEditor', icon: 'text' },
        titleName: 'textEditor'
      }
    ]
  },
  {
    id: '4',
    path: '/chart',
    component: Layout,
    redirect: '/chart/lineChart',
    name: 'chart',
    meta: { title: 'echart', icon: 'echart' },
    titleName: 'echart',
    children: [
      {
        path: 'lineChart',
        id: '4-1',
        name: 'lineChart',
        component: () => import('@/views/chart/lineChart'),
        meta: { title: 'lineChart', icon: 'line-chart' },
        titleName: 'lineChart'
      },
      {
        path: 'pieChart',
        id: '4-2',
        name: 'pieChart',
        component: () => import('@/views/chart/pieChart'),
        meta: { title: 'pieChart', icon: 'echarts-pie' },
        titleName: 'pieChart'
      },
      {
        path: 'barChart',
        id: '4-3',
        name: 'barChart',
        component: () => import('@/views/chart/barChart'),
        meta: { title: 'barChart', icon: 'bar' },
        titleName: 'barChart'
      }
    ]
  },
  {
    id: '5',
    path: '/theme',
    component: Layout,
    redirect: '/theme/index',
    name: 'theme',
    meta: { title: 'peeling', icon: 'theme' },
    titleName: 'theme',
    children: [
      {
        path: 'index',
        id: '5-1',
        name: 'Theme',
        component: () => import('@/views/theme/index'),
        meta: { title: 'peeling', icon: 'theme' },
        titleName: 'peeling',
        children: []
      }
    ]
  },

  { path: '*', redirect: '/404', hidden: true }
]

export default new Router({
  // mode: 'history', //后端支持可开
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRouterMap
})
